﻿<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/static/include/topLess.jsp"%>
<script>document.title="报表分组管理";</script>
<c:set var="reportTypeIds"></c:set>

<c:forEach items="${obj.dustryReports}" var="item">
	<c:set var="reportTypeIds" value="${reportTypeIds}${','}${item.reportTypeId}"></c:set>
</c:forEach>

<div style="width:100%">
	<div style="float:left; width:390px; height:450px">
		<form name="searchForm" action="" method="post">
		<input type="hidden" id="industry_id" value="${obj.id}">
		<input type="hidden" id="reportTypeIds" value="${reportTypeIds}">
		<input type="hidden" id="saveTypeIds">
		<input type="hidden" id="noReportTypeIds">
		<table>
			<tbody>				
				<tr class="tab_grey">
					<td>
						<span class="tab_text"> 海洋及相关产业分类： </span> 
						<input id="dustryName" type="text" name="dustryName" value="${obj.dustryName}" size="20" readonly class="tab_textbut_200" />
					</td>
				</tr>
				<tr class="tab_grey" style="height:360px">
					<td>
						<span class="tab_text"> 备注： </span> 
						<textarea id="dustryDesc" name="dustryDesc" style="color:#39a2d2" rows="20" cols="33">${obj.dustryDesc}</textarea>
					</td>
				</tr>
			</tbody>
		</table>
		</form>
	</div>
	<div style="float:left; width:540px; height:450px">
		<table>
			<tbody>				
				<tr class="tab_grey">
					<td>
						<span class="tab_text">报表版本:</span> 
						<select class="tab_textbut" id="reportVersion" onchange="queryReports()">
							
						</select>
						<span class="tab_text">报表制度:</span>
						<select class="tab_textbut_200" id="reportType" onchange="queryReportVersion()">
							<c:forEach items="${requestScope.reportTypeList}" var="vo">
								<option value="${vo.code}">${vo.codeName}</option>
							</c:forEach>
						</select>
					</td>
				</tr>				
			</tbody>
		</table>
		<div style="overflow:auto;height:350px">
			<table>
				<th colspan="2">报表名称（多选）</th>
				<tbody id="reportList">
				</tbody>
			</table>
		</div>
	</div>
	<c:if test="${empty param['edit']}">
	<div style="text-align:center">
		<a class="tab_but" href="#"	onclick="save()">保存</a>
		<a class="tab_but" href="#"	onclick="closeWin()">关闭</a>
	</div>
	</c:if>
</div>



<script type="text/javascript">

    $(function(){
    	
    	queryReportVersion();
    });

    function queryReportVersion(){
    	
    	var reportType = $("#reportType").val();
    	var url = "${baseURL}/report/queryReportVersion/" + reportType;
    	$.getJSON(url, function(result){
    		$("#reportVersion").empty();
    		$.each(result.operationResult, function(i, obj){
    			$("#reportVersion").append("<option value='" + obj.id + "'>" + obj.versionSystem + "</option>");
    		});
    		
    		queryReports();
    	});
    }
    
    function queryReports(){    	
    	var reportVersion = $("#reportVersion").val();
    	var reportType = $("#reportType").val();
    	var url = "${baseURL}/data/getReps";
    	var data = "versionId=" + reportVersion + "&typeId=" + reportType;

    	var loadi;
		$.ajax({
			url: url,
			type: 'post',
			data: data,
			dataType: 'json',
			beforeSend: function(){
				loadi = layer.load('加载中…');
			},
			complete: function(){
				layer.close(loadi);
			},
			success: function(msg){
				
				var typeTime = "";
				$("#reportList").empty();
				
				var checked = "";
	    		$.each(msg, function(i, obj){
	    			
	    			checked = "";
	    			
	    			if (obj.typeTime=="1"){
	    				typeTime = "（年报）";
	    			}else if (obj.typeTime=="2"){
	    				typeTime = "（季报）";
	    			}else{
	    				typeTime = "（月报）";
	    			}

	    			if ($("#reportTypeIds").val().indexOf(obj.id)>-1){
	    				checked = "checked";
	    				
	    			}
	    			
	    			$("#reportList").append("<tr><td><input type='checkbox' value='" + obj.id + "' " + checked + "></td><td>" + typeTime  + obj.typeName + "</td></tr>");

	    		});
	    		
	    		
    			$("input[type='checkbox']").each(function(){
    				$(this).bind("click", function(){
        				var noIds = $("#noReportTypeIds").val().split(",");
        				var ids = $("#reportTypeIds").val().split(",");
        				if (!this.checked){
        					if ($.inArray(this.value, ids)>-1){    						
        						if ($.inArray(this.value, noIds)==-1){
        							noIds.push(this.value);
        							$("#noReportTypeIds").val(noIds);
        						}
        	    			}
        				}else{
        					if ($.inArray(this.value,noIds)>-1){
        						noIds.splice($.inArray(this.value,noIds),1);
        						$("#noReportTypeIds").val(noIds);
        					}
        				}
    				});
    			});
			}
		});
    }
    
    function save(){
		
    	var ids = new Array();
    	$("input[type='checkbox']:checked").each(function(){
    		ids.push(this.value);
    	});
    	$("#saveTypeIds").val(ids);
    	
    	var url = "${baseURL}/reportgroup/modify";
    	var data = {id:'${obj.id}', dustryName:$("#dustryName").val(), 
    			dustryDesc:$("#dustryDesc").val(), 
    			reportTypes:$("#saveTypeIds").val(), 
    			noReportTypes:$("#noReportTypeIds").val(),
    			dl:'${obj.dl}',
    			zl:'${obj.zl}',
    			xl:'${obj.xl}'};
    	$.post(url, data, function(result){
    		if (result=="success"){
    			layer.msg("保存成功。", 1, 1);
    		}
    		
    		var reportTypeIds = $("#reportTypeIds").val().split(",");

    		$.each(ids, function(i, value){
				if ($.inArray(value, reportTypeIds)>-1){
					reportTypeIds.splice($.inArray(value, reportTypeIds), 1);
				}
    		});
    		$.merge(reportTypeIds, ids);
    		
    		if ($("#noReportTypeIds").val()!=""){
        		var noReportTypes = $("#noReportTypeIds").val().split(",");
        		$.each(noReportTypes, function(i, value){
        			if (value!=""){
        				reportTypeIds.splice($.inArray(value, reportTypeIds), 1);
        			}
        		});
    		}
    		$("#noReportTypeIds").val("");
    		$("#reportTypeIds").val(reportTypeIds);

    	}, 'json');
    }
    
    
    
</script>


<%@ include file="/static/include/bottom.jsp"%>
